import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseInterceptors,
  NotFoundException,
  UseFilters,
} from '@nestjs/common';
import { AuthService } from './auth.service';
import { CreateAuthDto } from './dto/create-auth.dto';
import { UpdateAuthDto } from './dto/update-auth.dto';
import { SysUser } from './entities/auth.entity';
import { ApiTags, ApiOperation, ApiBody, ApiResponse } from '@nestjs/swagger';
import { LoggingInterceptor } from './filter-login/LoginFilter';
import { SuccessResponse } from '../util/ResultResponse';
// import { HttpExceptionFilte
// r } from '../util/HttpExceptionFilter';

@ApiTags('auth') // 为控制器添加标签
@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  // 注册
  @Post('/signup')
  @ApiOperation({ summary: '用户注册' }) // 方法描述
  signup(@Body() signupData: SysUser): SuccessResponse<{  }> {
    const { password, username } = signupData;
    const data = this.authService.register(username, password);
    return { code: 0, data: data, message: '' };
  }

  // 登录
  @Post('/login')
  @ApiOperation({ summary: '用户登录' }) // 方法描述
  login(@Body() loginData: SysUser): SuccessResponse<{}> {
    // 在这个地方通过这个结果语法进行这个结构

    const { password, username } = loginData;
    const data = this.authService.login(username, password).catch((error) => {
      console.log(error);
    });
    return { code: 0, data: data, message: '' };
  }

  // 登录
  @Post('/')
  @ApiOperation({ summary: '用户登录' }) // 方法描述
  login1(@Body() loginData: SysUser): SuccessResponse<{}> {
    const { password, username } = loginData;
    const data = this.authService.login(username, password).catch((error) => {
      console.log(error);
    });
    return { code: 0, data: data, message: '' };
  }
}